/*****************************************************************************
 *
 *                      HUSONG PROPRIETARY INFORMATION
 *
 *          The information contained herein is proprietary to HUSONG
 *           and shall not be reproduced or disclosed in whole or in part
 *                    or used for any design or manufacture
 *              without direct written authorization from HUSONG.
 *
 *            Copyright (c) 2015 by HUSONG.  All rights reserved.
 *
 *****************************************************************************/
package me.send.data.service.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import me.send.data.service.mapper.ManagerMapper;
import me.send.data.service.pojo.Manager;
import me.send.data.service.pojo.ManagerPermission;
import me.send.data.service.pojo.ManagerPermissionTree;
import me.send.data.service.pojo.ManagerRole;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author maxmin
 *
 * @date 2015年9月15日 上午9:36:21
 */
@Service
public class ManagerService {
	
	@Autowired
	ManagerMapper managerMapper;
	
	/**
	 * 通过手机号码获取管理员
	 * @param telephone
	 * @return
	 * @author maxmin
	 * @date 2015年9月15日上午9:40:14
	 */
	public Manager getByTelephone(String telephone){
		return managerMapper.getByTelephone(telephone);
	}
	
	public List<ManagerRole> getManagerRolesByUser(Manager manager){
		return managerMapper.getManagerRolesByUser(manager);
	}
	
	public List<ManagerPermission> getManagerPermissionByRoles(List<ManagerRole> roles){
		Map<String,Object> params=new HashMap<String, Object>();
		params.put("roles", roles);
		return managerMapper.getManagerPermissionByRoles(params);
	}
	
	public List<ManagerPermissionTree> getManagerPermissionTreeByPermissions(List<ManagerPermission> perssions){
		Map<String,Object> params=new HashMap<String, Object>();
		params.put("perssions", perssions);
		return managerMapper.getManagerPermissionTreeByPermissions(params);
	}
	
	public void update(String username,String oldpassword,String newpassword){
		Map<String,Object> params=new HashMap<String, Object>();
		params.put("username", username);
		params.put("oldpassword", oldpassword);
		params.put("newpassword", newpassword);
		managerMapper.update(params);
	}
}
